#ifndef __SERVERCONF_H__
#define __SERVERCONF_H__

#include <string>

#include "config.h"

class ServerConf
{
public:
    const std::string& GetIp() const
    {
        return m_ip;
    }

    const int GetPort() const
    {
        return m_port;
    }

    void SetIp(std::string ip)
    {
        m_ip = ip;
    }

    void SetPort(int port)
    {
        m_port = port;
    }
private:
    std::string m_ip;
    int m_port;
};

template<>
class LexicalCast<std::string, ServerConf>
{
public:
    ServerConf operator()(const std::string& str)
    {
        YAML::Node node = YAML::Load(str);
        ServerConf serverConf;
        serverConf.SetIp(node["ip"].as<std::string>());
        serverConf.SetPort(node["port"].as<int>());
        return serverConf;
    }
};

template<>
class LexicalCast<ServerConf, std::string>
{
public:
    std::string operator()(const ServerConf& serverConf)
    {
        YAML::Node node;
        std::stringstream ss;
        node["ip"] = serverConf.GetIp();
        node["port"] = serverConf.GetPort();
        ss << node;
        return ss.str();
    }
};

#endif // !__SERVERCONF_H__
